import Http from "../utils/HttpUtil";
import URL from "./URL";
import MD5 from "../utils/MD5";
export default{
    async  UserLogin(phone,password){
        let url=URL.GetURL(URL.UserLogin);
        let md5Password=MD5.hex_md5(password);
        let para={phone,password:md5Password};
        return await(Http.Post(url,para))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },
    
    //注册
    //md5密码
    async  UserRegister(phone,SmsCode,password){
      
        let url=URL.GetURL(URL.UserRegister);
        let md5Password=MD5.hex_md5(password);
        //极光推送id
        let jiguangId="";
        let para={phone,SmsCode,password:md5Password,jiguangId};
        return await(Http.Post(url,para))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },
    
    // 查询个人信息
    async  SelectUserInformation(userId){
        let url=URL.GetURL(URL.selectUserInformation);
        let para={userId};
        return await(Http.Post(url,para))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },


    // update个人信息
    async  UpdateUserInformation(name,region,birthday,signature,labels,userId){
        let url=URL.GetURL(URL.UpdateUserInformation);
        let para={name,region,birthday,signature,labels,userId};
        // console.log(para);
        // return;
        return await(Http.Post(url,para))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },
    
    // 查询所有后台定义的标签
    async  SelectLabel(){
        let url=URL.GetURL(URL.SelectLabel);
        return await(Http.Get(url))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },
    
    // 查询所有后台定义的标签
    async  SelectUserDefineLabel(userId){
        let url=URL.GetURL(URL.SelectUserDefineLabel);
        console.log(url+"?userId="+userId)
        return await(Http.Get(url+"?userId="+userId))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },
    
    //  忘记密码
    async  UserForgetPassword(phone,smsCode,newPassword,confirmPassword){
        let url=URL.GetURL(URL.UserForgetPassword);
        let md5Password=MD5.hex_md5(newPassword);
        let md5ConfirmPassword=MD5.hex_md5(confirmPassword);
        let para={phone,smsCode,newPassword:md5Password,confirmPassword:md5ConfirmPassword};
        return await(Http.Post(url,para))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },
    
    //  修改密码
    async  UpdateLoginPassword(userId,oldPassword,newPassword,confirmPassword){
        let url=URL.GetURL(URL.UpdateLoginPassword);
        let md5oldPassword=MD5.hex_md5(oldPassword);
        let md5newPassword=MD5.hex_md5(newPassword);
        let md5confirmPassword=MD5.hex_md5(confirmPassword);
        
        let para={userId,oldPassword:md5oldPassword,
            newPassword:md5newPassword,confirmPassword:md5confirmPassword};
        return await(Http.Post(url,para))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },
    
    //  绑定QQ 
    async  BindingQQ(QQUserId,name,headUrl){
        let url=URL.GetURL(URL.BindingQQ);
        let para={QQUserId,name,headUrl};
        return await(Http.Post(url,para))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },
    
    // 绑定微信 
    async  BindingVX(WXUserId,name){
        let url=URL.GetURL(URL.BindingVX);
        let para={WXUserId,name};
        return await(Http.Post(url,para))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },
    
    //  绑定手机 
    async  BindingPhone(phone,userId,smsCode){
        let url=URL.GetURL(URL.BindingPhone);
        let para={phone,userId,smsCode};
        return await(Http.Post(url,para))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },
    
    //  解除绑定 
    async  RemoveQQOrVXBinding(status,userId){
        let url=URL.GetURL(URL.RemoveQQOrVXBinding);
        let para={status,userId};
        return await(Http.Post(url,para))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },

    //查询实名认证信息
    async SelectAuthenticationInformation(userId){
        let url=URL.GetURL(URL.SelectAuthenticationInformation);
        let para={userId};
        return await(Http.Post(url,para))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },

    //实名认证
    async UserRealNameAuthentication(userId,nationality,documentType,name,documentNumber){
        let url=URL.GetURL(URL.UserRealNameAuthentication);
        let para={userId,nationality,documentType,name,documentNumber};
        return await(Http.Post(url,para))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    },

    //修改手机号
    async UserReplacePhone(oldPhone,userId,newPhone,smsCode){
        let url=URL.GetURL(URL.UserReplacePhone);
        let para={oldPhone,userId,newPhone,smsCode};
        return await(Http.Post(url,para))
        .then(response=>{
            return(response);
        },reject=>{
            return Promise.reject(reject);
        });
    }
}